package org.ust.analyse;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jdt.core.dom.Type;

public class MethodDeclarationStructure
{

	private ArrayList < String >				modifiers;
	private ArrayList < String >				typeParameters;
	private Type								returnType;
	private String								methodName;
	private ArrayList < String >				parameters;
	private ArrayList < String >				exceptions;
	private boolean								isConstructor;

	/**
	 * ????? dont know how to bridge up invoking and being invoked functions.
	 */
	private List < MethodInvocationStructure >	invokingMethods;

	public MethodDeclarationStructure ( )
	{
		setInvokingMethods ( new ArrayList < MethodInvocationStructure > ( ) );
	}

	public ArrayList < String > getModifiers ( )
	{
		return modifiers;
	}

	public ArrayList < String > getTypeParameters ( )
	{
		return typeParameters;
	}

	public void setModifiers ( ArrayList < String > modifiers )
	{
		this.modifiers = modifiers;
	}

	public void setTypeParameters ( ArrayList < String > tmpArray )
	{
		this.typeParameters = tmpArray;
	}

	public void setReturnType ( Type returnType )
	{
		this.returnType = returnType;
	}

	public Type getReturnType ( )
	{
		return returnType;
	}

	public void setMethodName ( String methodName )
	{
		this.methodName = methodName;
	}

	public String getMethodName ( )
	{
		return methodName;
	}

	public void setParameters ( ArrayList < String > parameters )
	{
		this.parameters = parameters;
	}

	public ArrayList < String > getParameters ( )
	{
		return parameters;
	}

	public void setExceptions ( ArrayList < String > exceptions )
	{
		this.exceptions = exceptions;
	}

	public ArrayList < String > getExceptions ( )
	{
		return exceptions;
	}

	public void setConstructor ( boolean isConstructor )
	{
		this.isConstructor = isConstructor;
	}

	public boolean isConstructor ( )
	{
		return isConstructor;
	}

	public void setInvokingMethods (
			List < MethodInvocationStructure > invokingMethods )
	{
		this.invokingMethods = invokingMethods;
	}

	public List < MethodInvocationStructure > getInvokingMethods ( )
	{
		return invokingMethods;
	}

	@ SuppressWarnings ( "unchecked" )
	@ Override
	public String toString ( )
	{
		String output = "";

		Iterator it = getModifiers ( ).iterator ( );
		while ( it.hasNext ( ) )
		{
			String type = it.next ( ).toString ( );
			output += type + " ";
		}

		if ( getTypeParameters ( ) != null
				&& getTypeParameters ( ).size ( ) > 0 )
		{
			it = getTypeParameters ( ).iterator ( );
			while ( it.hasNext ( ) )
			{
				String type = it.next ( ).toString ( );
				output += type + " ";
			}
		}

		if ( getReturnType ( ) != null )
			output += getReturnType ( ) + " ";
		output += getMethodName ( ) + " ";

		it = getParameters ( ).iterator ( );
		while ( it.hasNext ( ) )
		{
			String type = it.next ( ).toString ( );
			output += type + " ";
		}

		it = getExceptions ( ).iterator ( );
		while ( it.hasNext ( ) )
		{
			String type = it.next ( ).toString ( );
			output += type + " ";
		}

		return output;
	}
}
